﻿using System;
using GalaSoft.MvvmLight;

namespace AzureTracer.Model
{
    public class AppSettings : ObservableObject, IAppSettings
    {
        private string _accountName;
        private string _accountKey;
        private int _maxDays;

        const string ACCOUNTNAME_PROPERTYNAME = "AccountName";
        const string ACCCOUNTKEY_PROPERTYNAME = "AccountKey";

        public string AccountName
        {
            get { return _accountName; }
            set
            {
                if (_accountName != value)
                {
                    _accountName = value;
                    RaisePropertyChanged(ACCOUNTNAME_PROPERTYNAME);
                }
            }
        }

        public string AccountKey
        {
            get { return _accountKey; }
            set
            {
                if (_accountKey != value)
                {
                    _accountKey = value;
                    RaisePropertyChanged(ACCCOUNTKEY_PROPERTYNAME);
                }
            }
        }

        public int MaxDaysSync
        {
            get { return _maxDays; }
            set
            {
                if (_maxDays != value)
                {
                    _maxDays = value;
                    RaisePropertyChanged("MaxDaysSync");
                }
            }
        }
        private bool _anySyncEnding;
        public bool AnySyncEnding
        {
            get { return _anySyncEnding; }
            set
            {
                if (_anySyncEnding == value) return;

                _anySyncEnding = value;
                RaisePropertyChanged("AnySyncEnding");
            }
        }

        public string LastKeySync { get; set; }      

        public int ScheduleTimeInMinutes { get; set; }

        public DateTime LastTimeSync { get; set; }

        public int BackgroundItemsCount { get; set; }

        public bool ReadyToSync()
        {
            return DateTime.Now > LastTimeSync.AddMinutes(ScheduleTimeInMinutes);
        }

        public AppSettings()
        {
            _accountName = string.Empty;
            _accountKey = string.Empty;
            _maxDays = 3;
            LastKeySync = string.Empty;
            LastTimeSync = DateTime.Today.AddMonths(-2);
            ScheduleTimeInMinutes = 60;
            _anySyncEnding = false;
        }
    }
}
